```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis配置加载机制解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background: #2d3748;
            color: #f8f8f2;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            overflow-x: auto;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 30%;
            background: rgba(110, 142, 251, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover:after {
            height: 50%;
            background: rgba(110, 142, 251, 0.3);
        }
        .section-divider {
            border: none;
            height: 1px;
            background: linear-gradient(90deg, rgba(167, 119, 227, 0) 0%, rgba(167, 119, 227, 0.5) 50%, rgba(167, 119, 227, 0) 100%);
            margin: 3rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-5xl mx-auto text-center">
            <div class="inline-block px-4 py-2 mb-6 bg-white bg-opacity-20 rounded-full backdrop-filter backdrop-blur-sm">
                <span class="text-sm font-semibold tracking-wider">MYBATIS 深度解析</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">MyBatis配置加载机制全解析</h1>
            <p class="text-xl md:text-2xl max-w-3xl mx-auto opacity-90 mb-8">从源码层面剖析MyBatis配置加载的核心流程与实现原理</p>
            <div class="flex justify-center space-x-4">
                <a href="#overview" class="px-6 py-3 bg-white text-purple-700 font-medium rounded-lg hover:bg-opacity-90 transition-all duration-300 shadow-lg">
                    <i class="fas fa-book-open mr-2"></i>开始阅读
                </a>
                <a href="#mermaid" class="px-6 py-3 border-2 border-white text-white font-medium rounded-lg hover:bg-white hover:bg-opacity-10 transition-all duration-300">
                    <i class="fas fa-project-diagram mr-2"></i>流程图解
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Overview Section -->
        <section id="overview" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-cogs text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">配置加载的作用与重要性</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">在MyBatis框架中，配置加载是整个框架初始化的第一步，负责加载并解析MyBatis的配置文件，进而初始化所有的配置信息。它包含了数据库连接池、SQL映射、类型处理器、缓存等重要组件的初始化过程。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-6">
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h3 class="text-xl font-semibold mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-file-code mr-2"></i>配置文件
                            </h3>
                            <p class="text-gray-700">MyBatis的配置文件通常为<code class="bg-gray-200 px-1 py-0.5 rounded">mybatis-config.xml</code>，其作用是定义全局配置，如数据库连接、映射文件路径、插件、日志等配置信息。</p>
                        </div>
                        <div class="bg-gray-50 p-6 rounded-lg border border-gray-200">
                            <h3 class="text-xl font-semibold mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-cogs mr-2"></i>初始化过程
                            </h3>
                            <p class="text-gray-700">配置加载的过程保证了系统能够正确初始化并启动，为后续的SQL执行和数据操作奠定基础。</p>
                        </div>
                    </div>
                    
                    <div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded-r-lg">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-info-circle text-blue-500 mr-3 mt-1"></i>
                            </div>
                            <div>
                                <p class="text-blue-800">配置加载阶段会解析并初始化所有核心组件，包括<strong>数据源</strong>、<strong>事务管理器</strong>、<strong>类型处理器</strong>、<strong>插件</strong>和<strong>映射器</strong>等。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <hr class="section-divider">

        <!-- SqlSessionFactoryBuilder Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-building text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">配置加载的核心类——<code class="bg-gray-100 px-2 py-1 rounded">SqlSessionFactoryBuilder</code></h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">MyBatis的配置加载过程从<code class="bg-gray-200 px-1 py-0.5 rounded">SqlSessionFactoryBuilder</code>类开始。<code class="bg-gray-200 px-1 py-0.5 rounded">SqlSessionFactoryBuilder</code>负责根据<code class="bg-gray-200 px-1 py-0.5 rounded">mybatis-config.xml</code>文件创建<code class="bg-gray-200 px-1 py-0.5 rounded">SqlSessionFactory</code>，它是MyBatis执行SQL的核心对象。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-java">public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(Reader reader) throws IOException {
        // 创建XMLConfigBuilder对象来解析配置文件
        XMLConfigBuilder parser = new XMLConfigBuilder(reader);
        // 解析配置文件，返回Configuration对象
        Configuration configuration = parser.parse();
        // 使用Configuration创建并返回SqlSessionFactory
        return new DefaultSqlSessionFactory(configuration);
    }
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-3 gap-4">
                        <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                            <h4 class="font-semibold text-purple-700 mb-2">XMLConfigBuilder</h4>
                            <p class="text-sm text-gray-600">负责解析XML文件并将配置转化为Configuration对象</p>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                            <h4 class="font-semibold text-purple-700 mb-2">Configuration</h4>
                            <p class="text-sm text-gray-600">MyBatis中的核心配置信息类，包含所有重要配置项</p>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                            <h4 class="font-semibold text-purple-700 mb-2">DefaultSqlSessionFactory</h4>
                            <p class="text-sm text-gray-600">SqlSessionFactory的标准实现类</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <hr class="section-divider">

        <!-- XMLConfigBuilder Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-file-alt text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800"><code class="bg-gray-100 px-2 py-1 rounded">XMLConfigBuilder</code>解析配置文件</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6"><code class="bg-gray-200 px-1 py-0.5 rounded">XMLConfigBuilder</code>是MyBatis的配置解析器，负责将XML配置文件解析为<code class="bg-gray-200 px-1 py-0.5 rounded">Configuration</code>对象。解析过程通过DOM解析器进行。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-java">public class XMLConfigBuilder extends XMLMapperBuilder {
    public Configuration parse() throws Exception {
        // 获取XML文档的根元素
        XNode root = document.getRootElement();
        // 解析配置节点
        parseConfiguration(root);
        return configuration;
    }
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h3 class="text-xl font-semibold mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-code mr-2"></i>关键方法解析
                            </h3>
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <span class="flex-shrink-0 inline-flex items-center justify-center h-6 w-6 rounded-full bg-purple-100 text-purple-600 mr-3">
                                        <i class="fas fa-angle-right text-xs"></i>
                                    </span>
                                    <span><code class="bg-gray-200 px-1 py-0.5 rounded">document.getRootElement()</code> 获取XML文档的根元素（通常是<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;configuration&gt;</code>节点）</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="flex-shrink-0 inline-flex items-center justify-center h-6 w-6 rounded-full bg-purple-100 text-purple-600 mr-3">
                                        <i class="fas fa-angle-right text-xs"></i>
                                    </span>
                                    <span><code class="bg-gray-200 px-1 py-0.5 rounded">parseConfiguration()</code>方法会将配置文件中的各个节点（如<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;settings&gt;</code>、<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;properties&gt;</code>、<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;mappers&gt;</code>等）逐一解析并加载到<code class="bg-gray-200 px-1 py-0.5 rounded">Configuration</code>对象中</span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-3 text-purple-700 flex items-center">
                                <i class="fas fa-sitemap mr-2"></i>解析流程
                            </h3>
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <ol class="list-decimal list-inside space-y-2">
                                    <li>读取并解析XML配置文件</li>
                                    <li>获取根节点<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;configuration&gt;</code></li>
                                    <li>遍历所有子节点进行配置初始化</li>
                                    <li>返回完整的<code class="bg-gray-200 px-1 py-0.5 rounded">Configuration</code>对象</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <hr class="section-divider">

        <!-- Configuration Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-database text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800"><code class="bg-gray-100 px-2 py-1 rounded">Configuration</code>类的初始化</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6"><code class="bg-gray-200 px-1 py-0.5 rounded">Configuration</code>类是MyBatis的核心配置类，保存着MyBatis的所有配置信息。它包含了数据库连接信息、映射器信息、插件、类型处理器等。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-java">public class Configuration {
    private String environment;
    private Properties properties = new Properties();
    private DataSource dataSource;
    private SqlSessionFactory sqlSessionFactory;
    
    // 一些配置信息初始化
    public void addMapper(Class<?> type) {
        // 添加映射器
        mappers.put(type.getName(), type);
    }
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h3 class="text-xl font-semibold mb-3 text-purple-700">初始化过程</h3>
                            <ul class="space-y-3 text-gray-700">
                                <li class="flex items-start">
                                    <span class="flex-shrink-0 inline-flex items-center justify-center h-6 w-6 rounded-full bg-purple-100 text-purple-600 mr-3">
                                        <i class="fas fa-check text-xs"></i>
                                    </span>
                                    <span>读取数据库连接池信息</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="flex-shrink-0 inline-flex items-center justify-center h-6 w-6 rounded-full bg-purple-100 text-purple-600 mr-3">
                                        <i class="fas fa-check text-xs"></i>
                                    </span>
                                    <span>初始化类型处理器</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="flex-shrink-0 inline-flex items-center justify-center h-6 w-6 rounded-full bg-purple-100 text-purple-600 mr-3">
                                        <i class="fas fa-check text-xs"></i>
                                    </span>
                                    <span>配置插件</span>
                                </li>
                                <li class="flex items-start">
                                    <span class="flex-shrink-0 inline-flex items-center justify-center h-6 w-6 rounded-full bg-purple-100 text-purple-600 mr-3">
                                        <i class="fas fa-check text-xs"></i>
                                    </span>
                                    <span>加载映射器</span>
                                </li>
                            </ul>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-3 text-purple-700">关键方法</h3>
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <div class="mb-3">
                                    <h4 class="font-medium text-purple-700 mb-1">addMapper()</h4>
                                    <p class="text-sm text-gray-600">会根据XML中的<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;mappers&gt;</code>节点加载所有的映射器类，映射器是SQL映射语句的集合</p>
                                </div>
                                <div>
                                    <h4 class="font-medium text-purple-700 mb-1">其他方法</h4>
                                    <p class="text-sm text-gray-600">还包括各种getter/setter方法，用于管理配置信息</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <hr class="section-divider">

        <!-- DataSource Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-plug text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">解析数据库连接配置</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">在<code class="bg-gray-200 px-1 py-0.5 rounded">mybatis-config.xml</code>配置文件中，数据库连接信息通常通过<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;environment&gt;</code>和<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;dataSource&gt;</code>节点进行配置。<code class="bg-gray-200 px-1 py-0.5 rounded">XMLConfigBuilder</code>会读取这些信息，并将其转化为相应的<code class="bg-gray-200 px-1 py-0.5 rounded">DataSource</code>对象。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-xml">&lt;configuration&gt;
    &lt;environments default="development"&gt;
        &lt;environment id="development"&gt;
            &lt;dataSource type="POOLED"&gt;
                &lt;property name="driver" value="com.mysql.cj.jdbc.Driver"/&gt;
                &lt;property name="url" value="jdbc:mysql://localhost:3306/mydb"/&gt;
                &lt;property name="username" value="root"/&gt;
                &lt;property name="password" value="root"/&gt;
            &lt;/dataSource&gt;
        &lt;/environment&gt;
    &lt;/environments&gt;
&lt;/configuration&gt;</code></pre>
                    </div>
                    
                    <div class="mb-6">
                        <h3 class="text-xl font-semibold mb-3 text-purple-700">DataSource类型</h3>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-medium text-purple-700 mb-2">POOLED</h4>
                                <p class="text-sm text-gray-600">使用连接池管理数据库连接，提高性能</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-medium text-purple-700 mb-2">UNPOOLED</h4>
                                <p class="text-sm text-gray-600">不使用连接池，每次操作创建新连接</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="code-block">
                        <pre><code class="language-java">public class XMLConfigBuilder {
    public void parseConfiguration(XNode root) throws Exception {
        // 解析<environments>节点，选择对应的数据库连接配置
        XNode environmentsNode = root.evalNode("environments");
        String environment = environmentsNode.getStringAttribute("default");
        // 解析<environment>节点，构建DataSource对象
        DataSourceFactory dataSourceFactory = new PooledDataSourceFactory();
        XNode environmentNode = environmentsNode.evalNode("environment[@id='" + environment + "']");
        dataSourceFactory.setProperties(environmentNode.getChildrenAsProperties());
        DataSource dataSource = dataSourceFactory.getDataSource();
    }
}</code></pre>
                    </div>
                    
                    <div class="mt-6 bg-yellow-50 border-l-4 border-yellow-400 p-4 rounded-r-lg">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-lightbulb text-yellow-500 mr-3 mt-1"></i>
                            </div>
                            <div>
                                <p class="text-yellow-800">在<code class="bg-yellow-100 px-1 py-0.5 rounded">parseConfiguration()</code>中，通过<code class="bg-yellow-100 px-1 py-0.5 rounded">evalNode()</code>方法获取<code class="bg-yellow-100 px-1 py-0.5 rounded">&lt;environments&gt;</code>和<code class="bg-yellow-100 px-1 py-0.5 rounded">&lt;environment&gt;</code>节点，进而构建<code class="bg-yellow-100 px-1 py-0.5 rounded">DataSource</code>对象。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <hr class="section-divider">

        <!-- TypeHandlers & Plugins Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-puzzle-piece text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">解析类型处理器和插件配置</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">MyBatis支持自定义类型处理器和插件，它们的配置通常在<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;typeHandlers&gt;</code>和<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;plugins&gt;</code>节点下。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-xml">&lt;configuration&gt;
    &lt;typeHandlers&gt;
        &lt;typeHandler handler="com.example.CustomTypeHandler"/&gt;
    &lt;/typeHandlers&gt;

    &lt;plugins&gt;
        &lt;plugin interceptor="com.example.CustomInterceptor"&gt;
            &lt;property name="someProperty" value="someValue"/&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/configuration&gt;</code></pre>
                    </div>
                    
                    <p class="text-lg text-gray-700 mb-6"><code class="bg-gray-200 px-1 py-0.5 rounded">XMLConfigBuilder</code>会读取这些配置，并将它们分别添加到<code class="bg-gray-200 px-1 py-0.5 rounded">Configuration</code>的<code class="bg-gray-200 px-1 py-0.5 rounded">typeHandlerRegistry</code>和<code class="bg-gray-200 px-1 py-0.5 rounded">pluginRegistry</code>中。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-java">public void parseConfiguration(XNode root) throws Exception {
    // 解析<TypeHandlers>节点，注册自定义类型处理器
    XNode typeHandlersNode = root.evalNode("typeHandlers");
    if (typeHandlersNode != null) {
        for (XNode typeHandlerNode : typeHandlersNode.getChildren()) {
            String handler = typeHandlerNode.getStringAttribute("handler");
            configuration.getTypeHandlerRegistry().register(handler);
        }
    }

    // 解析<Plugins>节点，注册插件
    XNode pluginsNode = root.evalNode("plugins");
    if (pluginsNode != null) {
        for (XNode pluginNode : pluginsNode.getChildren()) {
            String interceptor = pluginNode.getStringAttribute("interceptor");
            configuration.addInterceptor(interceptor);
        }
    }
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h3 class="text-xl font-semibold mb-3 text-purple-700">类型处理器</h3>
                            <p class="text-gray-700"><code class="bg-gray-200 px-1 py-0.5 rounded">getTypeHandlerRegistry()</code>方法将自定义类型处理器注册到<code class="bg-gray-200 px-1 py-0.5 rounded">Configuration</code>中，用于处理Java类型和数据库类型之间的转换。</p>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-3 text-purple-700">插件</h3>
                            <p class="text-gray-700"><code class="bg-gray-200 px-1 py-0.5 rounded">addInterceptor()</code>方法将插件注册到<code class="bg-gray-200 px-1 py-0.5 rounded">Configuration</code>中，允许开发者在MyBatis执行过程中拦截并修改操作。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <hr class="section-divider">

        <!-- Mapper Files Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-map text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800"><code class="bg-gray-100 px-2 py-1 rounded">Mapper</code>文件的加载与解析</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6"><code class="bg-gray-200 px-1 py-0.5 rounded">Mapper</code>文件通常用于定义具体的SQL语句，在<code class="bg-gray-200 px-1 py-0.5 rounded">mybatis-config.xml</code>中的<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;mappers&gt;</code>节点下配置。<code class="bg-gray-200 px-1 py-0.5 rounded">XMLConfigBuilder</code>会根据这些配置加载<code class="bg-gray-200 px-1 py-0.5 rounded">Mapper</code>文件并注册。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-xml">&lt;configuration&gt;
    &lt;mappers&gt;
        &lt;mapper resource="com/example/UserMapper.xml"/&gt;
    &lt;/mappers&gt;
&lt;/configuration&gt;</code></pre>
                    </div>
                    
                    <p class="text-lg text-gray-700 mb-6"><code class="bg-gray-200 px-1 py-0.5 rounded">XMLConfigBuilder</code>会读取<code class="bg-gray-200 px-1 py-0.5 rounded">&lt;mappers&gt;</code>节点，并通过<code class="bg-gray-200 px-1 py-0.5 rounded">parseMapper()</code>方法加载<code class="bg-gray-200 px-1 py-0.5 rounded">Mapper</code>文件。</p>
                    
                    <div class="code-block mb-6">
                        <pre><code class="language-java">public void parseConfiguration(XNode root) throws Exception {
    XNode mappersNode = root.evalNode("mappers");
    if (mappersNode != null) {
        for (XNode mapperNode : mappersNode.getChildren()) {
            String resource = mapperNode.getStringAttribute("resource");
            // 加载Mapper文件
            loadMapper(resource);
        }
    }
}

private void loadMapper(String resource) {
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource);
    mapperParser.parse();
}</code></pre>
                    </div>
                    
                    <div class="bg-green-50 border-l-4 border-green-500 p-4 rounded-r-lg">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-code-branch text-green-500 mr-3 mt-1"></i>
                            </div>
                            <div>
                                <p class="text-green-800">这里的<code class="bg-green-100 px-1 py-0.5 rounded">XMLMapperBuilder</code>负责解析具体的<code class="bg-green-100 px-1 py-0.5 rounded">Mapper.xml</code>文件，将SQL语句解析并映射到<code class="bg-green-100 px-1 py-0.5 rounded">MappedStatement</code>对象。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <hr class="section-divider">

        <!-- Mermaid Diagram Section -->
        <section id="mermaid" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-project-diagram text-purple-600"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">MyBatis配置加载流程图解</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="mermaid">
                        graph TD
                            A[开始] --> B[SqlSessionFactoryBuilder]
                            B --> C[创建XMLConfigBuilder]
                            C --> D[解析mybatis-config.xml]
                            D --> E{解析各节点}
                            E --> F[解析environments]
                            E --> G[解析typeHandlers]
                            E --> H[解析plugins]
                            E --> I[解析mappers]
                            F --> J[构建DataSource]
                            G --> K[注册TypeHandler]
                            H --> L[注册Interceptor]
                            I --> M[加载Mapper文件]
                            J --> N[创建Configuration]
                            K --> N
                            L --> N
                            M --> N
                            N --> O[创建SqlSessionFactory]
                            O --> P[结束]
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12">
        <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-xl font-bold mb-4">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition-colors duration-300">
                    <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```